package com.dduggs.note.thread.threadtest2;

/**
 * Created by ChenJiasheng on 2017/10/24.
 */

/**
 *  winTwo卖了一张票，还剩3张票
    winThree卖了一张票，还剩2张票
    winOne卖了一张票，还剩3张票
    winThree卖了一张票，还剩0张票
    winTwo卖了一张票，还剩1张票
 */
class MyThread extends Thread{

    private int ticketsCount = 5;//一共有5张火车票
    private String name; //窗口，也即是线程的名字

    public MyThread(String name){
        this.name=name;
    }

    @Override
    public void run() {
        while (ticketsCount>0){
            ticketsCount--;
            System.out.println(name+"卖了一张票，还剩"+ticketsCount+"张票");
        }
    }
}

public class TicketThread {

    public static void main(String[] args) {
        //创建3个线程，模拟三个窗口卖票
        MyThread mt1=new MyThread("winOne");
        MyThread mt2=new MyThread("winTwo");
        MyThread mt3=new MyThread("winThree");

        //启动这三个线程，开始抢票
        mt1.start();
        mt2.start();
        mt3.start();

    }

}
